home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / vbcc / statements.c < prev    next >
C/C++ Source or Header  |  1995-11-18  |  23KB  |  681 lines

  1. #include "vbc.h"
  2.  
  3. int cont_label=0;
  4. int test_assignment(struct Typ *,np);
  5.  
  6. void cr(void)
  7. /*  tested Registerbelegung */
  8. {
  9.     int i;
  10.     for(i=0;i<=MAXR;i++)
  11.         if(regs[i]!=regsa[i]) {error(149,regnames[i]);regs[i]=regsa[i];}
  12. }
  13. void statement(void)
  14. /*  bearbeitet ein statement                                    */
  15. {
  16.     char *merk;
  17.     cr();
  18.     killsp();
  19.     if(*s=='{'){
  20.         enter_block();
  21.         if(nesting>0) local_offset[nesting]=local_offset[nesting-1];
  22.         compound_statement();leave_block();return;}
  23.     merk=s;
  24.     cpbez(buff);
  25.     if(!strcmp("if",buff)){if_statement();return;}
  26.     if(!strcmp("switch",buff)){switch_statement();return;}
  27.     if(!strcmp("for",buff)){for_statement();return;}
  28.     if(!strcmp("while",buff)){while_statement();return;}
  29.     if(!strcmp("do",buff)){do_statement();return;}
  30.     if(!strcmp("goto",buff)){goto_statement();return;}
  31.     if(!strcmp("continue",buff)){continue_statement();return;}
  32.     if(!strcmp("break",buff)){break_statement();return;}
  33.     if(!strcmp("return",buff)){return_statement();return;}
  34.     if(!strcmp("case",buff)){labeled_statement();return;}
  35.     killsp();if(*s==':'){labeled_statement();return;}
  36.     /*  fehlt Aufruf der anderen statements */
  37.     s=merk;
  38.     expression_statement();
  39. }
  40. void labeled_statement(void)
  41. /*  bearbeitet labeled_statement                                */
  42. {
  43.     struct llist *lp;int def=0;
  44.     if(*s==':'){
  45.         s++;
  46.         if(!*buff){error(130);return;}
  47.         if(!strcmp("default",buff)){def=1;lp=0;} else lp=find_label(buff);
  48.         if(lp&&lp->flags&LABELDEFINED){error(131,buff);return;}
  49.         if(!lp) lp=add_label(buff);
  50.         lp->flags|=LABELDEFINED;
  51.         lp->switch_count=0;
  52.         if(def){
  53.             if(switch_act==0) error(150);
  54.             lp->flags|=LABELDEFAULT;
  55.             lp->switch_count=switch_act;
  56.         }
  57.         gen_label(lp->label);
  58.         afterlabel=0;
  59.     }else{
  60.         /*  case    */
  61.         np tree;struct llist *lp;
  62.         tree=expression();
  63.         killsp();
  64.         if(*s==':'){s++;killsp();} else error(70);
  65.         if(!switch_count){
  66.             error(132);
  67.         }else{
  68.             if(!tree||!type_expression(tree)){
  69.             }else{
  70.                 if(tree->flags!=CEXPR||tree->sidefx){
  71.                     error(133);
  72.                 }else{
  73.                     if((tree->ntyp->flags&31)<CHAR||(tree->ntyp->flags&31)>LONG){
  74.                         error(134);
  75.                     }else{
  76.                         lp=add_label(empty);
  77.                         lp->flags=LABELDEFINED;
  78.                         lp->switch_count=switch_act;
  79.                         eval_constn(tree);
  80.                         if(switch_typ==CHAR) lp->val.vchar=vchar;
  81.                         if(switch_typ==(UNSIGNED|CHAR)) lp->val.vuchar=vuchar;
  82.                         if(switch_typ==SHORT) lp->val.vshort=vshort;
  83.                         if(switch_typ==(UNSIGNED|SHORT)) lp->val.vushort=vushort;
  84.                         if(switch_typ==INT) lp->val.vint=vint;
  85.                         if(switch_typ==(UNSIGNED|INT)) lp->val.vuint=vuint;
  86.                         if(switch_typ==LONG) lp->val.vlong=vlong;
  87.                         if(switch_typ==(UNSIGNED|LONG)) lp->val.vulong=vulong;
  88.                         if(switch_typ==POINTER) lp->val.vpointer=vpointer;
  89.                         gen_label(lp->label);
  90.                     }
  91.                 }
  92.             }
  93.         }
  94.         if(tree) free_expression(tree);
  95.     }
  96.     cr();
  97.     killsp();statement();
  98. }
  99. void if_statement(void)
  100. /*  bearbeitet if_statement                                     */
  101. {
  102.     int ltrue,lfalse,lout,cexpr,cm;char *merk,buff[MAXI];
  103.     np tree;struct IC *new;
  104.     killsp(); if(*s=='(') s++; else error(151);
  105.     killsp();cm=nocode;
  106.     tree=expression();
  107.     if(!tree) {error(135);
  108.     }else{
  109.         ltrue=++label;lfalse=++label;
  110.         if(type_expression(tree)){
  111.             tree=makepointer(tree);
  112.             if(!arith(tree->ntyp->flags&15)&&(tree->ntyp->flags&15)!=POINTER)
  113.                 {error(136);
  114.             }else{
  115.                 gen_IC(tree,ltrue,lfalse);
  116.                 if(tree->flags==CEXPR){
  117.                     eval_const(&tree->val,tree->ntyp->flags&31);
  118.                     if(zdeq(vdouble)) cexpr=2; else cexpr=1;
  119.                 }else cexpr=0;
  120.                 if((tree->o.flags&SCRATCH)&&cexpr) free_reg(tree->o.reg);
  121.                 if(tree->o.flags&&!cexpr){
  122.                     new=(struct IC *)mymalloc(ICS);
  123.                     new->code=TEST;
  124.                     new->q1=tree->o;
  125.                     new->q2.flags=new->z.flags=0;
  126.                     new->typf=tree->ntyp->flags;
  127.                     add_IC(new);
  128.                     new=(struct IC *)mymalloc(ICS);
  129.                     new->code=BEQ;
  130.                     new->typf=lfalse;
  131.                     add_IC(new);
  132.                 }
  133.             }
  134.         }
  135.         free_expression(tree);
  136.     }
  137.     killsp(); if(*s==')') s++; else error(59);
  138.     if(cexpr==2) nocode=1;
  139.     if(!cexpr&&!tree->o.flags) gen_label(ltrue);
  140.     statement();
  141.     killsp();
  142.     merk=s;
  143.     cpbez(buff);
  144.     if(strcmp("else",buff)) {s=merk;nocode=cm;if(!cexpr) gen_label(lfalse);return;}
  145.     lout=++label;
  146.     if(!cexpr){
  147.         new=(struct IC *)mymalloc(ICS);
  148.         new->code=BRA;
  149.         new->typf=lout;
  150.         add_IC(new);
  151.         gen_label(lfalse);
  152.     }
  153.     if(cexpr==1) nocode=1; else nocode=cm;
  154.     statement();
  155.     if(!cexpr) gen_label(lout);
  156.     nocode=cm;
  157.     cr();
  158. }
  159. void switch_statement(void)
  160. /*  bearbeitet switch_statement                                 */
  161. {
  162.     np tree;int merk_typ,merk_count,merk_break;
  163.     struct IC *merk_fic,*merk_lic,*new;struct llist *lp;
  164.     killsp();
  165.     if(*s=='('){s++;killsp();} else error(151);
  166.     tree=expression(); killsp();
  167.     if(*s==')'){s++;killsp();} else error(59);
  168.     merk_typ=switch_typ;merk_count=switch_act;merk_break=break_label;
  169.     if(!tree){
  170.         error(137);
  171.     }else{
  172.         if(!type_expression(tree)){
  173.         }else{
  174.             if((tree->ntyp->flags&15)<CHAR||(tree->ntyp->flags&15)>LONG){
  175.                 error(138);
  176.             }else{
  177.                 int m1,m2,m3,def=0,rm;
  178.                 m3=break_label=++label;m1=switch_act=++switch_count;
  179.                 m2=switch_typ=tree->ntyp->flags&31;
  180.                 gen_IC(tree,0,0);
  181.                 if(!(tree->o.flags&SCRATCH)){
  182.                     new=(struct IC *)mymalloc(ICS);
  183.                     new->code=ASSIGN;
  184.                     new->q1=tree->o;
  185.                     new->q2.flags=0;
  186.                     new->q2.reg=sizetab[m2&15];
  187.                     get_scratch(&new->z,m2,0);
  188.                     new->typf=m2;
  189.                     add_IC(new);
  190.                     tree->o=new->z;
  191.                 }
  192.                 if((tree->o.flags&(SCRATCH|REG))==(SCRATCH|REG)){
  193.                     int r=tree->o.reg;
  194.                     rm=regs[r];
  195.                     regs[r]=regsa[r];
  196.                 }
  197.                 merk_fic=first_ic;merk_lic=last_ic;
  198.                 first_ic=last_ic=0;
  199.                 statement();
  200.                 if((tree->o.flags&(SCRATCH|REG))==(SCRATCH|REG)) regs[tree->o.reg]=rm;
  201.                 lp=first_llist;
  202.                 while(lp){
  203.                     if(lp->switch_count==m1){
  204.                         if(lp->flags&LABELDEFAULT){
  205.                             if(def) error(139);
  206.                             def=lp->label;
  207.                         }else{
  208.                             new=(struct IC *)mymalloc(ICS);
  209.                             new->q1.am=new->q2.am=new->z.am=0;
  210.                             new->code=COMPARE;
  211.                             new->typf=m2;
  212.                             new->q1=tree->o;
  213.                             new->q2.flags=KONST;
  214.                             new->q2.val=lp->val;
  215.                             new->z.flags=0;
  216.                             new->prev=merk_lic;
  217.                             if(merk_lic) merk_lic->next=new; else merk_fic=new;
  218.                             merk_lic=new;
  219.                             new=(struct IC *)mymalloc(ICS);
  220.                             new->q1.am=new->q2.am=new->z.am=0;
  221.                             new->code=BEQ;
  222.                             new->typf=lp->label;
  223.                             new->q1.flags=new->q2.flags=new->z.flags=0;
  224.                             new->prev=merk_lic;
  225.                             merk_lic->next=new;
  226.                             merk_lic=new;
  227.                         }
  228.                     }
  229.                     lp=lp->next;
  230.                 }
  231.                 if((tree->o.flags&(SCRATCH|REG))==(SCRATCH|REG)){   /* free_reg(tree->o.reg); */
  232.                     new=(struct IC *)mymalloc(ICS);
  233.                     new->q1.am=new->q2.am=new->z.am=0;
  234.                     new->code=FREEREG;new->typf=0;
  235.                     new->q2.flags=new->z.flags=0;
  236.                     new->q1.flags=REG;
  237.                     new->q1.reg=tree->o.reg;
  238.                     new->prev=merk_lic;
  239.                     if(merk_lic) merk_lic->next=new; else merk_fic=new;
  240.                     merk_lic=new;
  241.                     regs[tree->o.reg]=regsa[tree->o.reg];
  242.                 }
  243.                 new=(struct IC *)mymalloc(ICS);
  244.                 new->q1.am=new->q2.am=new->z.am=0;
  245.                 new->code=BRA;
  246.                 if(def) new->typf=def; else new->typf=m3;
  247.                 new->q1.flags=new->q2.flags=new->z.flags=0;
  248.                 if(merk_lic) merk_lic->next=new; else merk_fic=new;
  249.                 new->prev=merk_lic;
  250.                 first_ic->prev=new;
  251.                 new->next=first_ic;
  252.                 first_ic=merk_fic;
  253.                 gen_label(m3);
  254.             }
  255.         }
  256.     }
  257.     switch_typ=merk_typ;switch_act=merk_count;break_label=merk_break;
  258.     if(tree) free_expression(tree);
  259.     cr();
  260. }
  261. void while_statement(void)
  262. /*  bearbeitet while_statement                                  */
  263. {
  264.     np tree;int lloop,lin,lout,cm,cexpr,contm,breakm;
  265.     struct IC *new;
  266.     killsp();
  267.     if(*s=='(') {s++;killsp();} else error(151);
  268.     tree=expression();killsp();
  269.     if(*s==')') {s++;killsp();} else error(59);
  270.     cexpr=0;
  271.     if(tree){
  272.         if(type_expression(tree)){
  273.             tree=makepointer(tree);
  274.             if(!arith(tree->ntyp->flags&15)&&(tree->ntyp->flags&15)!=POINTER){
  275.                 error(140);
  276.                 cexpr=-1;
  277.             }else{
  278.                 if(tree->flags==CEXPR){
  279.                     eval_const(&tree->val,tree->ntyp->flags&31);
  280.                     if(zdeq(vdouble)) cexpr=1; else cexpr=2;
  281.                     if(cexpr==1) error(152);
  282.                 }
  283.             }
  284.         }else cexpr=-1;
  285.     } else error(141);
  286.     lloop=++label;lin=++label;lout=++label;cm=nocode;
  287.     contm=cont_label;breakm=break_label;
  288.     if(!cexpr||tree->sidefx) cont_label=lin; else cont_label=lloop;
  289.     if(!cexpr||tree->sidefx){
  290.         new=(struct IC *)mymalloc(ICS);
  291.         new->code=BRA;
  292.         new->typf=lin;
  293.         add_IC(new);
  294.     }
  295.     if(cexpr!=1) gen_label(lloop);
  296.     cm=nocode;break_label=lout;
  297.     if(cexpr==1) nocode=1;
  298.     currentpri*=looppri;
  299.     statement();
  300.     nocode=cm;cont_label=contm;break_label=breakm;
  301.     if(!cexpr||tree->sidefx) gen_label(lin);
  302.     if(tree&&cexpr>=0){
  303.         if(cexpr!=1||tree->sidefx){
  304.             gen_IC(tree,lloop,lout);
  305.             if((tree->o.flags&SCRATCH)&&cexpr) free_reg(tree->o.reg);
  306.         }
  307.         if(tree->o.flags&&!cexpr){
  308.             new=(struct IC *)mymalloc(ICS);
  309.             new->code=TEST;
  310.             new->typf=tree->ntyp->flags&31;
  311.             new->q1=tree->o;
  312.             new->q2.flags=new->z.flags=0;
  313.             add_IC(new);
  314.             new=(struct IC *)mymalloc(ICS);
  315.             new->code=BNE;
  316.             new->typf=lloop;
  317.             add_IC(new);
  318.         }
  319.         if(cexpr==2){
  320.             new=(struct IC *)mymalloc(ICS);
  321.             new->code=BRA;
  322.             new->typf=lloop;
  323.             add_IC(new);
  324.         }
  325.     }
  326.     if(tree) free_expression(tree);
  327.     gen_label(lout);
  328.     currentpri/=looppri;
  329.     cr();
  330. }
  331. void for_statement(void)
  332. /*  bearbeitet for_statement                                    */
  333. {
  334.     np tree1=0,tree2=0,tree3=0;int lloop,lin,lout,cm,cexpr,contm,breakm;
  335.     struct IC *new;
  336.     killsp();
  337.     if(*s=='(') {s++;killsp();} else error(59);
  338.     if(*s!=';'){tree1=expression();killsp();}
  339.     if(tree1){
  340.         if(tree1->flags==POSTINC) tree1->flags=PREINC;
  341.         if(tree1->flags==POSTDEC) tree1->flags=PREDEC;
  342.         if(type_expression(tree1)){
  343.             if(tree1->sidefx){
  344.                 gen_IC(tree1,0,0);
  345.                 if(tree1&&(tree1->o.flags&SCRATCH)) free_reg(tree1->o.reg);
  346.             }else{error(153);}
  347.         }
  348.         free_expression(tree1);
  349.     }
  350.     cexpr=0;
  351.     if(*s==';') {s++;killsp();} else error(54);
  352.     if(*s!=';') {tree2=expression();killsp();} else {cexpr=2;}
  353.     if(*s==';') {s++;killsp();} else error(54);
  354.     if(*s!=')') {tree3=expression();killsp();}
  355.     if(*s==')') {s++;killsp();} else error(59);
  356.     if(tree3){
  357.         if(!type_expression(tree3)){
  358.             free_expression(tree3);
  359.             tree3=0;
  360.         }
  361.     }
  362.     if(tree2){
  363.         if(type_expression(tree2)){
  364.             tree2=makepointer(tree2);
  365.             if(!arith(tree2->ntyp->flags&15)&&(tree2->ntyp->flags&15)!=POINTER){
  366.                 error(142);
  367.                 cexpr=-1;
  368.             }else{
  369.                 if(tree2->flags==CEXPR){
  370.                     eval_const(&tree2->val,tree2->ntyp->flags&31);
  371.                     if(zdeq(vdouble)) cexpr=1; else cexpr=2;
  372.                     if(cexpr==1) error(152);
  373.                 }
  374.             }
  375.         }else cexpr=-1;
  376.     }
  377.     lloop=++label;lin=++label;lout=++label;cm=nocode;
  378.     contm=cont_label;breakm=break_label;
  379.     cont_label=++label;break_label=lout;
  380.     if(!cexpr||(tree2&&tree2->sidefx)){
  381.         new=(struct IC *)mymalloc(ICS);
  382.         new->code=BRA;
  383.         new->typf=lin;
  384.         add_IC(new);
  385.     }
  386.     if(cexpr!=1) gen_label(lloop);
  387.     cm=nocode;
  388.     if(cexpr==1) nocode=1;
  389.     currentpri*=looppri;
  390.     statement();
  391.     nocode=cm;
  392.     gen_label(cont_label);
  393.     cont_label=contm;break_label=breakm;
  394.     if(tree3){
  395.         if(tree3->flags==POSTINC) tree3->flags=PREINC;
  396.         if(tree3->flags==POSTDEC) tree3->flags=PREDEC;
  397.         if(tree3->sidefx){
  398.             gen_IC(tree3,0,0);
  399.             if(tree3&&(tree3->o.flags&SCRATCH)) free_reg(tree3->o.reg);
  400.         }else error(153);
  401.         free_expression(tree3);
  402.     }
  403.     if(!cexpr||(tree2&&tree2->sidefx)) gen_label(lin);
  404.     if(tree2&&cexpr>=0){
  405.         if(cexpr!=1||tree2->sidefx){
  406.             gen_IC(tree2,lloop,lout);
  407.             if((tree2->o.flags&SCRATCH)&&cexpr) free_reg(tree2->o.reg);
  408.         }
  409.         if(tree2->o.flags&&!cexpr){
  410.             new=(struct IC *)mymalloc(ICS);
  411.             new->code=TEST;
  412.             new->typf=tree2->ntyp->flags&31;
  413.             new->q1=tree2->o;
  414.             new->q2.flags=new->z.flags=0;
  415.             add_IC(new);
  416.             new=(struct IC *)mymalloc(ICS);
  417.             new->code=BNE;
  418.             new->typf=lloop;
  419.             add_IC(new);
  420.         }
  421.         if(cexpr==2){
  422.             new=(struct IC *)mymalloc(ICS);
  423.             new->code=BRA;
  424.             new->typf=lloop;
  425.             add_IC(new);
  426.         }
  427.     }
  428.     if(!tree2&&cexpr==2){
  429.         new=(struct IC *)mymalloc(ICS);
  430.         new->code=BRA;
  431.         new->typf=lloop;
  432.         add_IC(new);
  433.     }
  434.     if(tree2) free_expression(tree2);
  435.     gen_label(lout);
  436.     currentpri/=looppri;
  437.     cr();
  438. }
  439. void do_statement(void)
  440. /*  bearbeitet do_statement                                     */
  441. {
  442.     np tree;int lloop,lout,contm,breakm;
  443.     struct IC *new;
  444.     lloop=++label;lout=++label;currentpri*=looppri;
  445.     gen_label(lloop);
  446.     breakm=break_label;contm=cont_label;cont_label=++label;break_label=lout;
  447.     statement();
  448.     killsp();
  449.     gen_label(cont_label);cont_label=contm;break_label=breakm;
  450.     cpbez(buff);killsp();
  451.     if(strcmp("while",buff)) error(154);
  452.     if(*s=='(') {s++;killsp();} else error(151);
  453.     tree=expression();
  454.     if(tree){
  455.         if(type_expression(tree)){
  456.             tree=makepointer(tree);
  457.             if(arith(tree->ntyp->flags&15)||(tree->ntyp->flags&15)==POINTER){
  458.                 if(tree->flags==CEXPR){
  459.                     eval_const(&tree->val,tree->ntyp->flags&31);
  460.                     if(tree->sidefx) gen_IC(tree,0,0);
  461.                     if(!zdeq(vdouble)){
  462.                         new=(struct IC *)mymalloc(ICS);
  463.                         new->code=BRA;
  464.                         new->typf=lloop;
  465.                         add_IC(new);
  466.                     }
  467.                 }else{
  468.                     gen_IC(tree,lloop,lout);
  469.                     if(tree->o.flags){
  470.                         new=(struct IC *)mymalloc(ICS);
  471.                         new->code=TEST;
  472.                         new->typf=tree->ntyp->flags&31;
  473.                         new->q1=tree->o;
  474.                         new->q2.flags=new->z.flags=0;
  475.                         add_IC(new);
  476.                         new=(struct IC *)mymalloc(ICS);
  477.                         new->code=BNE;
  478.                         new->typf=lloop;
  479.                         add_IC(new);
  480.                     }
  481.                 }
  482.             }else error(143);
  483.         }
  484.         free_expression(tree);
  485.     }
  486.     killsp();
  487.     if(*s==')') {s++;killsp();} else error(59);
  488.     if(*s==';') {s++;killsp();} else error(54);
  489.     gen_label(lout);
  490.     currentpri/=looppri;
  491.     cr();
  492. }
  493. void goto_statement(void)
  494. /*  bearbeitet goto_statement                                   */
  495. {
  496.     struct llist *lp;
  497.     struct IC *new;
  498.     killsp();cpbez(buff);
  499.     if(!*buff) error(144);
  500.     killsp();
  501.     if(*s==';'){s++;killsp();} else error(54);
  502.     lp=find_label(buff);
  503.     if(!lp) lp=add_label(buff);
  504.     lp->flags|=LABELUSED;
  505.     new=(struct IC *)mymalloc(ICS);
  506.     new->typf=lp->label;
  507.     new->code=BRA;
  508.     new->typf=lp->label;
  509.     add_IC(new);
  510.     cr();
  511. }
  512. void continue_statement(void)
  513. /*  bearbeitet continue_statement                               */
  514. {
  515.     struct IC *new;
  516.     killsp();
  517.     if(*s==';') {s++;killsp();} else error(54);
  518.     if(cont_label==0){error(145);return;}
  519.     new=(struct IC *)mymalloc(ICS);
  520.     new->code=BRA;
  521.     new->typf=cont_label;
  522.     add_IC(new);
  523.     cr();
  524. }
  525. void break_statement(void)
  526. /*  bearbeitet break_statement                                  */
  527. {
  528.     struct IC *new;
  529.     killsp();
  530.     if(*s==';') {s++;killsp();} else error(54);
  531.     if(break_label==0){error(146);return;}
  532.     new=(struct IC *)mymalloc(ICS);
  533.     new->code=BRA;
  534.     new->typf=break_label;
  535.     add_IC(new);
  536.     cr();
  537. }
  538. void return_statement(void)
  539. /*  bearbeitet return_statement                                 */
  540. {
  541.     np tree;
  542.     struct IC *new;
  543.     killsp();
  544.     if(*s!=';'){
  545.         if(tree=expression()){
  546.             killsp();
  547.             if(*s==';') {s++;killsp();} else error(54);
  548.             if(!return_typ){
  549.                 if(type_expression(tree)){
  550.                     tree=makepointer(tree);
  551.                     if((tree->ntyp->flags&15)!=VOID)
  552.                         error(155);
  553.                     gen_IC(tree,0,0);
  554.                     if(tree->o.flags&SCRATCH) free_reg(tree->o.reg);
  555.                 }
  556.             }else{
  557.                 if(type_expression(tree)){
  558.                     tree=makepointer(tree);
  559.                     if(!test_assignment(return_typ,tree)){free_expression(tree);return;}
  560.                     gen_IC(tree,0,0);
  561.                     convert(tree,return_typ->flags&31);
  562.                     new=(struct IC *)mymalloc(ICS);
  563.                     new->code=ASSIGN;
  564.                     new->typf=return_typ->flags&31;
  565.                     new->q1=tree->o;
  566.                     new->q2.flags=0;
  567.                     new->q2.reg=szof(return_typ);
  568.                     if(freturn(return_typ)){
  569.                         new->z.flags=SCRATCH|REG;
  570.                         new->z.reg=freturn(return_typ);
  571.                         if(!regs[new->z.reg]){
  572.                             struct IC *alloc=mymalloc(ICS);
  573.                             alloc->code=ALLOCREG;
  574.                             alloc->q1.flags=REG;
  575.                             alloc->q2.flags=alloc->z.flags=0;
  576.                             alloc->q1.reg=new->z.reg;
  577.                             add_IC(alloc);
  578.                             regs[new->z.reg]=1;
  579.                         }
  580.                     }else{
  581.                         new->z.reg=0;
  582.                         new->z.v=return_var;
  583.                         new->z.flags=SCRATCH|VAR;
  584.                         new->z.val.vlong=l2zl(0L);
  585.                     }
  586.                     add_IC(new);
  587.                     /*  das hier ist nicht sehr schoen, aber wie sonst? */
  588.                     if(new->z.flags&SCRATCH&®s[new->z.reg]) free_reg(new->z.reg);
  589.                 }
  590.             }
  591.             free_expression(tree);
  592.         }else{
  593.             if(return_typ) error(156);
  594.         }
  595.     }else{ s++; if(return_typ) error(156);}
  596.  
  597.     new=(struct IC *)mymalloc(ICS);
  598.     new->code=BRA;
  599.     new->typf=return_label;
  600.     add_IC(new);
  601.     cr();
  602. }
  603.  
  604. void expression_statement(void)
  605. /*  bearbeitet expression_statement                             */
  606. {
  607.     np tree;
  608.     killsp();
  609.     if(*s==';') {s++;return;}
  610.     if(tree=expression()){
  611.         if(tree->flags==POSTINC) tree->flags=PREINC;
  612.         if(tree->flags==POSTDEC) tree->flags=PREDEC;
  613.         if(type_expression(tree)){
  614.             if(DEBUG&2){pre(stdout,tree);printf("\n");}
  615.             if(tree->sidefx){
  616.                 gen_IC(tree,0,0);
  617.                 if((tree->o.flags&(SCRATCH|REG))==REG) ierror(0);
  618.                 if(tree&&(tree->o.flags&SCRATCH)) free_reg(tree->o.reg);
  619.             }else{error(153);if(DEBUG&2) prd(stdout,tree->ntyp);}
  620.         }
  621.         free_expression(tree);
  622.     }
  623.     killsp();
  624.     if(*s==';') s++; else error(54);
  625.     cr();
  626. }
  627. void compound_statement(void)
  628. /*  bearbeitet compound_statement (block)                       */
  629. {
  630.     killsp();
  631.     if(*s=='{') s++; else error(157);
  632.     killsp();
  633.     while(declaration(0)){
  634.         var_declaration();
  635.         killsp();
  636.     }
  637.     while(*s!='}'){
  638.         statement();
  639.         killsp();
  640.     }
  641.     s++;killsp();
  642. }
  643. struct llist *add_label(char *identifier)
  644. /*  Fuegt label in Liste                                        */
  645. {
  646.     struct llist *new;
  647.     new=(struct llist *)mymalloc(LSIZE);
  648.     new->next=0;new->label=++label;new->flags=0;
  649.     new->identifier=add_identifier(identifier,strlen(identifier));
  650.     if(first_llist==0){
  651.         first_llist=last_llist=new;
  652.     }else{
  653.         last_llist->next=new;
  654.         last_llist=new;
  655.     }
  656.     return(last_llist); /* return(new) sollte aequiv. sein */
  657. }
  658. struct llist *find_label(char *identifier)
  659. /*  Sucht Label, gibt Zeiger auf llist oder 0 beu Fehler zurueck    */
  660. {
  661.     struct llist *p;
  662.     p=first_llist;
  663.     while(p){
  664.         if(!strcmp(p->identifier,identifier)) return(p);
  665.         p=p->next;
  666.     }
  667.     return(0);
  668. }
  669. void free_llist(struct llist *p)
  670. /*  Gibt llist frei                                             */
  671. {
  672.     struct llist *merk;
  673.     while(p){
  674.         merk=p->next;
  675.         if(!(p->flags&LABELDEFINED)) error(147,p->identifier);
  676.         if(!(p->flags&LABELUSED)&&!p->switch_count) error(148,p->identifier);
  677.         free(p);
  678.         p=merk;
  679.     }
  680. }
  681.